﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAO_ADMIN;
using System.Data.SqlClient;
using DBMS;
using System.Data;
using DTO;
namespace DAO
{
    public class BenhNhanDAO
    {
        static public DataTable DanhSachBenhNhan(string key)
        {
            string procName = "sp_DanhSachBenhNhan";
            SqlParameter output = new SqlParameter();
            DBMS.DBMS dbms = new DBMS.DBMS();
            List<SqlParameter> parr = new List<SqlParameter>();
            parr.Add(new SqlParameter("@CMND", key));
            DataTable dt = DataProvider.SelectStoreProcedure(procName, parr);
            return dt;
        }

        static public DataTable DanhSachBenhNhan_CMND(string key)
        {
            string procName = "sp_DanhSachBenhNhan_CMND";
            SqlParameter output = new SqlParameter();
            DBMS.DBMS dbms = new DBMS.DBMS();
            List<SqlParameter> parr = new List<SqlParameter>();
            parr.Add(new SqlParameter("@CMND", key));
            DataTable dt = DataProvider.SelectStoreProcedure(procName, parr);
            return dt;
        }

        static public bool ThemBenhNhan(BenhNhanDTO bnDto)
        {
            bool re = false;
            
            string procName = "sp_ThemMoiHoSoBenhNhan";

            SqlConnection con = DataProvider.ConnectionData();
            SqlCommand cmd = new SqlCommand(procName, con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@CMND", bnDto.CMND));
            cmd.Parameters.Add(new SqlParameter("@DienThoai", bnDto.DienThoai));
            cmd.Parameters.Add(new SqlParameter("@HoTen", bnDto.HoTen));
            cmd.Parameters.Add(new SqlParameter("@NgaySinh", bnDto.NgaySinh));
            cmd.Parameters.Add(new SqlParameter("@DiaChi", bnDto.DiaChi));
            cmd.Parameters.Add(new SqlParameter("@GioiTinh", bnDto.GioiTinh));
            cmd.Parameters.Add(new SqlParameter("@SoThe", bnDto.SoThe));
            cmd.Parameters.Add(new SqlParameter("@NgayHetHang", bnDto.NgayHetHan));
            cmd.Parameters.Add(new SqlParameter("@TinhTrang", bnDto.TinhTrang));

            if (cmd.ExecuteNonQuery() != 0) re = true;

            return re;
        }
    }
}
